﻿using System.Collections.Generic;
using System.Linq;
using Gola.VN.Scb.Web.Bll;
using Gola.VN.Scb.Web.Common.Entities;

namespace Gola.VN.Scb.Web.Presentation.Models
{
    internal class ProviderService : BaseService
    {
        internal ProviderService(MainBiz mainBiz)
            : base(mainBiz)
        {
        }

        internal int Insert(ProviderEntity provider)
        {
            var package = new BizPackage();
            package.Model = ModelType.Provider;
            package.Event = BizEvent.InsertProvider;
            package.Input = provider;

            _mainBiz.Execute(package);

            return (int)package.Output;
        }

        internal int Update(ProviderEntity provider)
        {
            var package = new BizPackage();
            package.Model = ModelType.Provider;
            package.Event = BizEvent.UpdateProvider;
            package.Input = provider;

            _mainBiz.Execute(package);

            return (int)package.Output;
        }

        internal List<ProviderEntity> GetProviderAllLocations()
        {
            var package = new BizPackage();
            package.Model = ModelType.Provider;
            package.Event = BizEvent.GetProviders;

            _mainBiz.Execute(package);

            return package.Output as List<ProviderEntity>;
        }

        internal ProviderEntity GetProvider(string name)
        {
            var package = new BizPackage();
            package.Model = ModelType.Provider;
            package.Event = BizEvent.GetProviders;
            package.Input = name;

            _mainBiz.Execute(package);

            return package.Output as ProviderEntity;
        }

        internal ProviderEntity GetProvider(int id)
        {

            var package = new BizPackage();
            package.Model = ModelType.Provider;
            package.Event = BizEvent.GetProviders;
            package.Input = id;

            _mainBiz.Execute(package);

            return package.Output as ProviderEntity;
        }


        internal List<ProviderEntity> GetCustomers()
        {
            IEnumerable<ProviderEntity> providers = GetProviderAllLocations();

            return (from p in providers where p.ExpressionId == ProductsBll.VirtualExpressionId select p).ToList();
        }
    }
}